package com.xq;

import com.xq.pojo.User;
import com.xq.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * Hello world!
 *
 */
public class App {
    public static void main( String[] args ) {
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        UserService userService = context.getBean(UserService.class);
        // 测试搭建
//        testConnection(userService);
        // 测试添加
        User user = new User(null, "小明",19, "123456");
//        testAdd(userService,user);
        // 测试修改
//        user = new User(32, "小明N",19, "123456");
//        testUpdate(userService,user);
        // 测试删除
//        int i = userService.deleteByPrimaryKey(32);
        // 测试获取
        user = userService.selectByPrimaryKey(3);
        System.out.println(user);
    }

    /**
     * 测试是否搭建成功
     * @param userService
     */
    public static void testConnection(UserService userService) {
        List<User> list = userService.getAll();
        for (User user : list) {
            System.out.println(user);
        }
    }

    /**
     * 添加测试
     * @param userService
     * @param user
     */
    public static void testAdd(UserService userService, User user) {
        userService.insert(user);
    }
    /**
     * 修改测试
     * @param userService
     * @param user
     */
    public static void testUpdate(UserService userService, User user) {
        userService.updateByPrimaryKey(user);
    }
}
